﻿using System;
using System.Data;
using System.Configuration;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using StillVoiceCommon;
using TN5Y;
using Microsoft.ApplicationBlocks.Data;
using System.Data.SqlClient;

namespace TeamTime.Classes
{
    public class Programme: DataTableRow
   {
       //public string CompanyName { get; set; }
       public string FullNameAndID { get; set; }
       public Programme()
       {
           this.initClass(Utilities.DBConnectionString, "Programme");
       }
       public new void load(Int32 id)
       {
           base.load(id);
           //System.Data.SqlClient.SqlDataReader dr = SqlHelper.ExecuteReader(TN5Y.Utilities.DBConnectionString, CommandType.Text,
           //     "select * from Programme where ID = @id",
           //     new SqlParameter("id", id));

           //if (dr.Read())
           //{
               
               
           //}
           //dr.Close();
           //dr = null;
       }

       
    }

    public class EnterpriseProgramme : DataTableRow
    {
        
        public string CompanyName { get; set; }
        public string ProgrammeName { get; set; }
        public EnterpriseProgramme()
        {
            this.initClass(Utilities.DBConnectionString, "EnterpriseProgramme");
        }
        public new void load(Int32 id)
        {
            base.load(id);
            System.Data.SqlClient.SqlDataReader dr = SqlHelper.ExecuteReader(TN5Y.Utilities.DBConnectionString, CommandType.Text,
                 "select * from ViewEnterpriseProgrammes where ID = @id",
                 new SqlParameter("id", id));

            if (dr.Read())
            {
                ProgrammeName = dr["ProgrammeName"].ToString();
                CompanyName = dr["CompanyName"].ToString();
            }
            dr.Close();
            dr = null;
        }
    }

    public class EnterpriseProgrammes
    {
        public DataSet search(Int32 enterpriseID, Int32 programmeID)
        {
            string sql = "select * from ViewEnterpriseProgrammes  where 1=1 ";
            if (enterpriseID > 0)
            {
                sql += " and EnterpriseID = @EnterpriseID";
            }
            if (programmeID > 0)
            {
                sql += " and ProgrammeID = @ProgrammeID";
            }
            return SqlHelper.ExecuteDataset(TN5Y.Utilities.DBConnectionString, CommandType.Text,sql                ,
                new SqlParameter("EnterpriseID", enterpriseID),
                new SqlParameter("ProgrammeID", programmeID));
        }

        internal Int32 getDuplicateID(Int32 enterpriseID, Int32 programmeID, Int32 ID)
        {
            Int32 ret = 0;
            string sql = "select ID from EnterpriseProgramme where EnterpriseID = @EnterpriseID and ProgrammeID = @ProgrammeID ";
            if (ID > 0) { sql += " and ID <> @ID"; }//same attributes, different id
            SqlDataReader dr;
            dr = SqlHelper.ExecuteReader(TN5Y.Utilities.DBConnectionString, CommandType.Text, sql,
                new SqlParameter("EnterpriseID", enterpriseID),
                new SqlParameter("ProgrammeID", programmeID),
                new SqlParameter("ID", ID));
            if (dr.Read())
            {
                ret = Convert.ToInt32(dr[0]);
            }
            dr.Close();
            return ret;
        }
    }
}
